package com.xz;

import com.xz.list.LinkedList;
import com.xz.list.List;

/**
 * @author XZ
 * @create 2021-04-23 22:39
 */
public class Deque<E> implements DequeDao<E> {
    private List<E> list = new LinkedList<>();

    @Override
    public int size() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void clear() {
        list.clear();
    }

    @Override
    public E deQueueRear() {
        return list.remove(size() - 1);
    }

    @Override
    public E deQueueFront() {
        return list.remove(0);
    }

    @Override
    public E front() {
        return list.get(0);
    }

    @Override
    public E rear() {
        return list.get(size() - 1);
    }

    @Override
    public void enQueueRear(Object element) {
        list.add((E) element);
    }

    @Override
    public void enQueueFront(Object element) {
        list.add(0, (E) element);
    }
}
